package com.spring.springbootswaggerstudy.controller;

import com.google.common.collect.Maps;
import com.spring.springbootswaggerstudy.entity.User;
import io.swagger.annotations.*;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.Map;

@RestController
@RequestMapping("/users")
@Api(value = "user", description = "用户管理", produces = MediaType.APPLICATION_JSON_VALUE)
public class UserController {
//    @RequestMapping("/getUser")
//    public User getUser(){
//        return new User();
//    }

    @RequestMapping(value = "/get", method = RequestMethod.GET)
    @ApiOperation(value = "获取用户接口", notes = "获取用户接口详细描述")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "header", dataType = "string", name = "token", value = "访问凭证", required = true),
    })
    public User getUser(String username, String password) {
        return new User(username, password);
    }

    @RequestMapping(value = "/post", method = RequestMethod.POST)
    @ApiOperation(value = "创建用户接口", notes = "创建用户接口详细描述")
    public Map<String, Object> post(User user) {
        System.out.println(user);
        HashMap<String, Object> map = Maps.newHashMap();
        map.put("username", "are you ok");
        map.put("password", "ok");
        return map;
    }

    @ApiOperation("name的接口")
    @PostMapping("/name")
    @ResponseBody
    public String name(@ApiParam("这个名字会被返回") String username) {
        return username;
    }




}
